package com.wh.webflux.config;

import com.wh.webflux.handler.DelayHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * @description:
 * @author: GooGoo
 * @time: 2023/4/10 12:09
 */
@Configuration
public class RouterConfiguration {
    @Bean
    RouterFunction<ServerResponse> delayRouterFunction(DelayHandler delayHandler) {
        return RouterFunctions.nest(RequestPredicates.path("/delays"),
                RouterFunctions.route(RequestPredicates.GET("/getAllDelays"), delayHandler::getAllDelays)
                        .andRoute(RequestPredicates.POST("/addDelay"), delayHandler::addDelay)
                        .andRoute(RequestPredicates.DELETE("/{id}"), delayHandler::deleteDelays));
    }

}
